package class08;

public class Code06_ConvertToLetterString {

	public static int number(String str) {
		if (str == null || str.length() == 0) {
			return 0;
		}
		return process(str.toCharArray(), 0);
	}

	public static int process(char[] str, int i) {
		if (i == str.length) { // base case
			return 1;
		}
		if (str[i] == '0') {
			return 0;  // 在[0..i-1]都已经确定的情况下，i位置如果是0，没办法解析
		}
		if (str[i] == '1') {
			int res = process(str, i + 1);
			if (i + 1 < str.length) {
				res += process(str, i + 2);
			}
			return res;
		}
		if (str[i] == '2') {
			int res = process(str, i + 1);
			if (i + 1 < str.length && (str[i + 1] >= '0' && str[i + 1] <= '6')) {
				res += process(str, i + 2);
			}
			return res;
		}
		return process(str, i + 1);
	}

	public static void main(String[] args) {
		System.out.println(number("1111111"));
	}

}
